package bandidong.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "tbl_customer", catalog = "web_ban_di_dong_db", schema = "", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"customer_email"})})
@XmlRootElement
public class Customer implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "customer_id", nullable = false)
    private Integer customerId;
    
    @Size(min = 1, max = 200)
    @Column(name = "customer_name", length = 200)
    private String customerName;
    
    @Size(min = 1, max = 500)
    @Column(name = "customer_address", length = 500)
    private String customerAddress;
    
    @Size(min = 1, max = 50)
    @Column(name = "customer_phone_number", length = 50)
    private String customerPhoneNumber;
    
    @Size(max = 200)
    @Column(name = "customer_email", length = 200)
    private String customerEmail;
    
    @Size(max = 200)
    @Column(name = "customer_password", length = 200)
    private String customerPassword;
    
    @Size(max = 200)
    @Column(name = "customer_account_number", length = 200)
    private String customerAccountNumber;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer", fetch = FetchType.EAGER)
    private Set<Orders> ordersSet = new HashSet<Orders>();

    public Customer() {
    }

    public Customer(Integer customerId, String customerName, String customerAddress, 
            String customerPhoneNumber, String customerEmail, String customerPassword, 
            String customerAccountNumber) {
        this.customerId = customerId;
        this.customerName = customerName;
        this.customerAddress = customerAddress;
        this.customerPhoneNumber = customerPhoneNumber;
        this.customerEmail = customerEmail;
        this.customerPassword = customerPassword;
        this.customerAccountNumber = customerAccountNumber;
    }
    
    public Customer(Integer customerId, String customerName, String customerAddress, 
            String customerPhoneNumber, String customerEmail, String customerPassword, 
            String customerAccountNumber, Set<Orders> ordersSet) {
        this(customerId, customerName, customerAddress, customerPhoneNumber, customerEmail, customerPassword, customerAccountNumber);
        this.ordersSet = ordersSet;
    }

    public Integer getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getCustomerAddress() {
        return customerAddress;
    }

    public void setCustomerAddress(String customerAddress) {
        this.customerAddress = customerAddress;
    }

    public String getCustomerPhoneNumber() {
        return customerPhoneNumber;
    }

    public void setCustomerPhoneNumber(String customerPhoneNumber) {
        this.customerPhoneNumber = customerPhoneNumber;
    }

    public String getCustomerEmail() {
        return customerEmail;
    }

    public void setCustomerEmail(String customerEmail) {
        this.customerEmail = customerEmail;
    }

    public String getCustomerPassword() {
        return customerPassword;
    }

    public void setCustomerPassword(String customerPassword) {
        this.customerPassword = customerPassword;
    }

    public String getCustomerAccountNumber() {
        return customerAccountNumber;
    }

    public void setCustomerAccountNumber(String customerAccountNumber) {
        this.customerAccountNumber = customerAccountNumber;
    }

    public Set<Orders> getOrdersSet() {
        return ordersSet;
    }

    public void setOrdersSet(Set<Orders> ordersSet) {
        this.ordersSet = ordersSet;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (customerId != null ? customerId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.customerId == null && other.customerId != null) || (this.customerId != null && !this.customerId.equals(other.customerId))) {
            return false;
        }
        return true;
    }
}
